<?php

namespace catchAdmin\smstag\controller;

use catchAdmin\smstag\request\SmsTagRequest;
use catcher\base\CatchRequest;
use catcher\base\CatchRequest as Request;
use catcher\CatchResponse;
use catcher\base\CatchController;
use catchAdmin\smstag\model\SmsTag as SmsTagModel;
use think\Response;

class SmsTag extends CatchController
{

    protected SmsTagModel $smsTagModel;

    /**
     * SmsTag constructor.
     * @param SmsTagModel $smsTagModel
     */
    public function __construct(SmsTagModel $smsTagModel)
    {
        $this->smsTagModel = $smsTagModel;
    }

    /**
     *
     * @time 2022/10/08 11:22
     * @return Response
     */
    public function index(): Response
    {
        return CatchResponse::success($this->smsTagModel->getList());
    }

    /**
     * @param SmsTagRequest $request
     * @return Response
     */
    public function save(SmsTagRequest $request): Response
    {
        return CatchResponse::success($this->smsTagModel->storeBy($request->post()));
    }

    /**
     *
     * @time 2022/10/08 11:22
     * @param $id
     * @return Response
     */
    public function read($id): Response
    {
        return CatchResponse::success($this->smsTagModel->findBy($id));
    }

    /**
     * @param $id
     * @param SmsTagRequest $request
     * @return Response
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function update($id, SmsTagRequest $request): Response
    {
        return CatchResponse::success($this->smsTagModel->updateBy($id, $request->post()));
    }

    /**
     *
     * @time 2022/10/08 11:22
     * @param $id
     * @return Response
     */
    public function delete($id): Response
    {
        return CatchResponse::success($this->smsTagModel->deleteBy($id));
    }

    public function getTagByTopicId(CatchRequest $request)
    {
        $result = $this->smsTagModel->getTagsByTopicId();
        return CatchResponse::success($result);
    }
}